{% extends 'base.html' %}
{% load mytags %}
{% block self_head_css_js %}
    <script src="/static/layer/layer.js"></script>
    <script src="/static/js/base.js"></script>
    <script src="/static/plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="/static/plugins/datatables/dataTables.bootstrap.min.js"></script>
    <script src="/static/plugins/datatables/dataTables.bootstrap.css"></script>
{% endblock %}
{% block content %}

    <script>
        window.onload=init;
        function init() {
            var box = document.getElementById("branches");
            box.className="active";
            var box2 = document.getElementById("branch");
            box2.className="active";
        }
    </script>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
    </section>

    <!-- Main content -->
    <section class="content">
        <form action="" method="post" id="branch_form">
                {% csrf_token %}
            <div class="box">
                <div class="box-header">
                    <div class="btn btn-group" style="padding-left: 0">
						 <a id="branchadd" style="display: none;" href="{% url 'branch_add' %}" class="btn btn-success">添加分支</a>
                  </div>
                </div>

                <!-- /.box-header -->
                <div class="box-body">
                  <table class="table table-striped table-bordered" id="branchform">
                      <thead>
                        <tr>
                            <th>
                                <input id="checkall" type="checkbox" class="i-checks" name="checkall" value="checkall" data-editable='false' onclick="check_all('branch_form')">
                            </th>
                            <th>分支名称</th>
                            <th>分支地址</th>
                            <th>负责人</th>
                            <th>联系电话</th>
                            <th>操作</th>
                        </tr>
                      </thead>
                            <tbody>
                            {% for branch in all_branch %}
                                <tr class="even gradeX">
                                    <td><input type="checkbox" id="id" class="i-checks" value="{{ branch.id }}" name="id" /></td>
                                    <td><a href="#"><li style="list-style-type:none" onclick="return popWin(this.value)" value="{{ branch.id }}">{{ branch.name }}</li></a> </td>
                                    <td>{{ branch.address }} </td>
                                    <td>{{ branch.owner.name }} </td>
                                    <td>{{ branch.owner.phone }} </td>
                                    <td>
                                        <a id="branchedit" style="display: block; float:left; margin: auto;" href="{% url "branch_edit" branch.id %}"><span class="btn btn-sm btn-info">编辑</span></a>
                                        <a id="branchdel" style="display: block; float:left; margin: auto;" href="{% url "branch_del"%}?id={{ branch.id }}" onclick="return confirm('删除分支？')"><span class="btn btn-sm btn-danger ">删除</span></a>
                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                  </table>
                  <div class="btn-group">
{#                      <input type="button" id="region_del" class="btn btn-danger"   name="del_button" value="删除区域"/>#}
                  </div>
                </div>
            </div>
        </form>
    </section>

</div>
<script>
  $(function () {
    $('#branchform').DataTable({
      "paging": true,
      "lengthChange": true,
      "searching": true,
      "ordering": true,
      "info": true,
      "bAutoWidth": false
    });
  });
</script>

<script>
    $('#region_del').click(function () {
        var region_id_all = getIDall();
        if (region_id_all == ''){
            alert("请至少选择一行!");
            return false;
        }
        if (confirm("确定删除?")) {
            $.ajax({
                type: "post",
                data: {region_id_all: region_id_all,csrfmiddlewaretoken: '{{ csrf_token }}'},
                url: "{% url 'region_del' %}",
                success: function () {
                    parent.location.reload();
                }
            });
        }
    });
</script>

<script>
function popWin(region_id){
  layer.open({
      type: 2,
      title: '项目列表',
      area: ['700px', '500px'],
      shadeClose: true, //点击遮罩关闭
      content: ['/branches/branchresourceinfo/' + region_id]
  });
}
</script>
{% endblock %}
